<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>茶旅联盟</title>
    <link rel="stylesheet" href="http://cache.amap.com/lbs/static/main1119.css"/>
    <style>
        .info-tip {
            position: absolute;
            top: 10px;
            right: 10px;
            font-size: 12px;
            background-color: #fff;
            height: 35px;
            text-align: left;
        }
    </style>
    <script src="http://cache.amap.com/lbs/static/es5.min.js"></script>
    <script src="http://webapi.amap.com/maps?v=1.4.1&key=67532b9196d91df7b5d2583c8389d4b5"></script>
    <script type="text/javascript" src="http://cache.amap.com/lbs/static/addToolbar.js"></script>
    <script type="text/javascript" src="/LianniuWeb/tea/js/jquery-1.11.3.min.js"></script>
    <script type="text/javascript" src="/LianniuWeb/js/commons/commons.js"></script>
</head>
<body>
	<div id="container"></div>
	<script type="text/javascript">
		$(function(){
			//这是茶旅联盟的显示图片，这个位置信息有两个作用，一是显示图片，二是绑定图片事件
			//var imgPath = 'http://webapi.amap.com/theme/v1.3/markers/n/mark_b2.png';
			var imgPath = '/LianniuWeb/sideShowPic/tea.jpg';
			var proList;
			$.ajax({
				type : "get",
				url : server_url
						+ 'rest/tea/product/getTeaClubList.do?ran=' + Math.random(),
				dataType : 'json',
				async : true,
				data : {
					token : token
				},
				success : function(result) {
					proList = result.data;
					console.log(result);
					var lat = localStorage.getItem("lat"); //纬度
					var log = localStorage.getItem("lon"); //经度
					var map = new AMap.Map('container', {
				        resizeEnable: true,
				        center: [log,lat],
				        zoom: 13
				    });    
				    map.clearMap();  // 清除地图覆盖物
				    var markers = [];
				    markers.push({icon: 'http://webapi.amap.com/theme/v1.3/markers/n/mark_b1.png',
				        position: [log, lat]});
				    $.each(proList,function(i,n){
				    	markers.push({
				    		icon: imgPath,
					        position: [n.teaProLon, n.teaProLat],
					        productid:n.productid
				    	});
				    });
				   /*  var markers = [{
				        icon: 'http://webapi.amap.com/theme/v1.3/markers/n/mark_b1.png',
				        position: [log, lat]
				    },{
				        icon: 'http://webapi.amap.com/theme/v1.3/markers/n/mark_b1.png',
				        position: [116.21, 39.91]
				    }, {
				        icon: 'http://webapi.amap.com/theme/v1.3/markers/n/mark_b2.png',
				        position: [116.37, 39.91]
				    }, {
				        icon: 'http://webapi.amap.com/theme/v1.3/markers/n/mark_b3.png',
				        position: [116.31, 39.81]
				    }]; */
				    // 添加一些分布不均的点到地图上,地图上添加三个点标记，作为参照
				    markers.forEach(function(marker) {
				        var mapMaker = new AMap.Marker({
				            map: map,
				            icon: marker.icon,
				            position: [marker.position[0], marker.position[1]],
				            offset: new AMap.Pixel(-12, -36)
				        });
				        AMap.event.addListener(mapMaker, 'click', function() {
				            //alert(marker.productid);
				            if(!marker.productid){
				            	return;
				            }
				            localStorage.setItem('productId',marker.productid);
				            var param = {};
							param.productId = marker.productid;
							param.longitude = marker.position[0];
							param.latitude  = marker.position[1];
							//跳转
							localStorage.setItem('param',JSON.stringify(param));
							window.location = server_url + "teaClub.do";
				        });
				    });
				    var center = map.getCenter(); 
				}
			});	
		});
	</script>
</body>
</html>